/**
 * Copyright (c) 2023 murenchao
 * taomu is licensed under Mulan PubL v2.
 * You can use this software according to the terms and conditions of the Mulan PubL v2.
 * You may obtain a copy of Mulan PubL v2 at:
 *       http://license.coscl.org.cn/MulanPubL-2.0
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PubL v2 for more details.
 */
package cool.taomu.box.datasource

import com.google.inject.Provider
import com.google.inject.name.Named
import com.mchange.v2.c3p0.ComboPooledDataSource
import javax.inject.Inject
import javax.sql.DataSource

class C3p0DataSourceProvider implements Provider<DataSource> {
	ComboPooledDataSource dataSource = new ComboPooledDataSource();

	@Inject
	def void setDirver(@Named("c3p0.jdbc.driver") String driverCLass) {
		dataSource.setDriverClass = driverCLass;
	}

	@Inject
	def void setJdbcUrl(@Named("c3p0.jdbc.url") String url) {
		dataSource.setJdbcUrl = url;
	}

	@Inject
	def void setUname(@Named("c3p0.jdbc.username") String uname) {
		dataSource.setUser = uname;
	}

	@Inject
	def void setPasswd(@Named("c3p0.jdbc.password") String pwd) {
		dataSource.setPassword = pwd;
	}
	
	@Inject
	def void maxPoolSize(@Named("c3p0.maxPoolSize") int value) {
		dataSource.maxPoolSize = value;
	}

	@Inject
	def void testConnectionOnCheckin(@Named("c3p0.testConnectionOnCheckin") boolean value) {
		dataSource.testConnectionOnCheckin = value;
	}

	@Inject
	def void testConnectionOnCheckout(@Named("c3p0.testConnectionOnCheckout") boolean value) {
		dataSource.testConnectionOnCheckout = value;
	}

	@Inject
	def void minPoolSize(@Named("c3p0.minPoolSize") int value) {
		dataSource.minPoolSize = value
	}


	@Inject
	def void breakAfterAcquireFailure(@Named("c3p0.breakAfterAcquireFailure") boolean value) {
		dataSource.breakAfterAcquireFailure = value
	}

	@Inject
	def void setAcquireIncrement(@Named("c3p0.acquireIncrement") int value) {
		dataSource.acquireIncrement = value
	}

	@Inject
	def void setInitialSize(@Named("c3p0.initialPoolSize") int value) {
		dataSource.initialPoolSize = value
	}
	
	@Inject
	def void acquireRetryAttempts(@Named("c3p0.acquireRetryAttempts") int value) {
		dataSource.acquireRetryAttempts = value
	}
	@Inject
	def void acquireRetryDelay(@Named("c3p0.acquireRetryDelay") int value) {
		dataSource.acquireRetryDelay = value
	}
	@Inject
	def void autoCommitOnClose(@Named("c3p0.autoCommitOnClose") boolean value) {
		dataSource.autoCommitOnClose = value
	}
	@Inject
	def void automaticTestTable(@Named("c3p0.automaticTestTable") String value) {
		dataSource.automaticTestTable = value
	}
	@Inject
	def void checkoutTimeout(@Named("c3p0.checkoutTimeout") int value) {
		dataSource.checkoutTimeout = value
	}
	@Inject
	def void dataSourceName(@Named("c3p0.dataSourceName") String value) {
		dataSource.dataSourceName = value
	}
	@Inject
	def void loginTimeout(@Named("c3p0.loginTimeout") int value) {
		dataSource.loginTimeout = value 
	}
	@Inject
	def void maxConnectionAge(@Named("c3p0.maxConnectionAge") int value) {
		dataSource.maxConnectionAge= value 
	}
	@Inject
	def void maxIdleTime(@Named("c3p0.maxIdleTime") int value) {
		dataSource.maxIdleTime= value 
	}
	@Inject
	def void maxIdleTimeExcessConnections(@Named("c3p0.maxIdleTimeExcessConnections") int value) {
		dataSource.maxIdleTimeExcessConnections= value 
	}

	override get() {
		return dataSource;
	}
}
